package com.freesky.biz.abchina.controller;

import com.freesky.biz.abchina.domain.TCreditActivity;
import com.freesky.biz.abchina.service.ICreditActivityService;
import com.freesky.biz.icbc.domain.TMarketingActivity;
import com.freesky.biz.icbc.service.IMarketingActivityService;
import com.freesky.biz.utils.SeqUtil;
import com.freesky.common.annotation.Log;
import com.freesky.common.core.controller.BaseController;
import com.freesky.common.core.domain.AjaxResult;
import com.freesky.common.core.page.TableDataInfo;
import com.freesky.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 信用卡权益
 */
@RestController
@RequestMapping("/abchina/credit/activity")
public class CreditActivityController extends BaseController {

    @Autowired
    private ICreditActivityService creditActivityService;

    @PreAuthorize("@ss.hasPermi('abchina:credit:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCreditActivity entity) {
        startPage();
        List<TCreditActivity> list = creditActivityService.selectCreditActivityList(entity);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('abchina:credit:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable String activityId) {
        return success(creditActivityService.selectCreditActivityById(activityId));
    }


    @PreAuthorize("@ss.hasPermi('abchina:credit:add')")
    @Log(title = "信用卡权益", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TCreditActivity entity) {
        entity.setCreateBy(String.valueOf(getUserId()));
        entity.setId(SeqUtil.getSeqId());
        return toAjax(creditActivityService.insertCreditActivity(entity));
    }


    @PreAuthorize("@ss.hasPermi('abchina:credit:edit')")
    @Log(title = "信用卡权益", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TCreditActivity entity) {
        entity.setUpdateBy(String.valueOf(getUserId()));
        return toAjax(creditActivityService.updateCreditActivity(entity));
    }

    @PreAuthorize("@ss.hasPermi('abchina:credit:remove')")
    @Log(title = "信用卡权益", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable String[] activityIds) {
        return toAjax(creditActivityService.deleteCreditActivityByIds(activityIds));
    }

}
